package org.laizili.solution.leetcode;

import java.util.ArrayList;
import java.util.List;

/**
 * <a href="https://leetcode-cn.com/problems/self-dividing-numbers/">728. 自除数</a>
 * <p>
 * tags: 模拟;
 * </p>
 */
public class Problem728 {

    private static class Solution {
        public List<Integer> selfDividingNumbers(int left, int right) {
            List<Integer> resList = new ArrayList<>();
            for (int i = left; i <= right; i++) {
                if (isDividingNumber(i))
                    resList.add(i);
            }
            return resList;
        }

        private boolean isDividingNumber(int num) {
            // helper function
            int n = num;
            while (n > 0) {
                int bit = n % 10;
                if (bit == 0 || num % bit != 0) {
                    return false;
                }
                n /= 10;
            }
            return true;
        }
    }
}
